
{extend name='bus@public/index'}
{block name="css"}{/block}
{block name="main"}
<link rel="stylesheet" href="/static/ssimg/ssimg.css">
<style>
    .ssimg{
        width:100px !important;
        height:100px !important;
        border-radius:50%;
    }

    .ssimg >img{
        border-radius:50%;
    }
</style>
<!--用户新增/编辑-->
<div class="form  mr-3" style="padding-top:20px" ng-controller="BasicsInfoController">
    <div class="form-row">
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="name">姓名</label>
            <input type="text" class="form-control col-8" id="name" name="name" autocomplete="off" ng-model="model.name" >
        </div>
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="name">账户</label>
            <input type="text" class="form-control col-8" id="account" name="account" autocomplete="off" ng-model="model.account" >
        </div>
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="name">密码</label>
            <input type="password" class="form-control col-8" id="password" name="password" autocomplete="off" ng-model="model.password" >
        </div>
        <div class="form-inline col-6 form-group">
            <span class="font-weight-light">请填写6到12位密码，修改时密码留空则不改密码</span>
        </div>
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="status">状态</label>
            <select class="form-control col-8" name="status" id="status" ng-model="model.status" ng-options="o.id as o.name for o in status"></select>
        </div>
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="role_id">角色</label>
            <select class="form-control col-8" name="role_id" id="role_id" ng-model="model.role_id" ng-options="o.id as o.name for o in role"></select>
        </div>
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="department_id">部门</label>
            <select class="form-control col-8" name="department_id" id="department_id" ng-model="model.department_id" ng-options="o.id as o.name for o in department"></select>
        </div>
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="position_id">职位</label>
            <select class="form-control col-8" name="position_id" id="position_id" ng-model="model.position_id" ng-options="o.id as o.name for o in position"></select>
        </div>
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="mobile">电话</label>
            <input type="text" class="form-control col-8" id="mobile" name="mobile" autocomplete="off" ng-model="model.mobile" >
        </div>
        <div class="form-inline col-6 form-group">
            <label class="col-3" for="remark">供应商</label>
            <input type="text" class="form-control col-8" id="remark" name="remark" autocomplete="off" ng-model="model.remark" >
        </div>
    </div>
    <div class="text-center mt-2">
        <input type='hidden' value='{$Think.get.id}' name='id'/>
        <button type="button" class="btn btn-secondary btn-cancel"> 取消 </button>
        <button type="button" class="btn btn-primary ml-2" ng-click="Submit()"> 保存 </button>
    </div>
</div>
{/block}
{block name="script"}
<script src="/static/ssimg/ssimg.js"></script>
<script>
    let PageConfig = {
        InfoUrl:'/admin/user/info_data',
        SubmitUrl:'/admin/user/post_data'
    }




</script>
<script>
    app.controller("BasicsInfoController", function($scope, $http, dataFactory) {
        //绑定下拉框
        $scope.department = [];
        $scope.role = [];
        $scope.position = [];
        $scope.status = [];
        $scope.sex = [];
        $scope.shift = [];
        dataFactory.SelectDepartment().then(function (data) {
            $scope.department = data;
        });
        dataFactory.SelectRole().then(function (data) {
            $scope.role = data;
        });
        dataFactory.SelectPosition().then(function (data) {
            $scope.position = data;
        });
        dataFactory.SelectStatus().then(function (data) {
            $scope.status = data;
        });
        $scope.model = {
            id:$("[name='id']").val(),
            name: '',
            account: '',
            password:'',
            status:'正常',
            role_id:0,
            department_id:0,
            position_id:0,
            mobile:'',
            mail:'',
        };
        //编辑加载数据
        $scope.LoadInfo = function(){
            $scope.model.id = $("[name='id']").val();
            if($scope.model.id != 0){
                let index = layer.load(2 ,{ icon: 2 ,shade: 0.1 });
                $http({
                    method: 'GET',
                    url: PageConfig.InfoUrl,
                    cache: false,
                    params: { id: $scope.model.id }
                }).success(function (result, status, headers, config) {
                    layer.close(index);
                    if (result.code == 0) {
                        $scope.model = result.data;
                        $('.ssimg>img').attr('src',result.data.img);
                    }
                    $("#wx_name").data('id',$scope.model.openid);
                }).error(function (result, status, headers, config) {
                    layer.close(index);
                    oob.show({code:-1,msg:"请求过程中发生异常"});
                });
            }
        };
        //保存数据
        $scope.Submit = function(){
            let index = layer.load(2 ,{ icon: 2 ,shade: 0.1 });
            $scope.model.openid = $("#wx_name").data('id');
            $http({
                method: 'POST',
                url: PageConfig.SubmitUrl,
                cache: false,
                params: $scope.model
            }).success(function (result, status, headers, config) {
                oob.show(result,function () {
                    layer.close(index);
                    if (result.code == 0) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.bind();
                    }
                });
            }).error(function (result, status, headers, config) {
                layer.close(index);
                oob.show({code:-1,msg:"请求过程中发生异常"});
            });
        };
        $(function () {
            $scope.LoadInfo();
        });


    });
</script>
{/block}



